package com.lavida.project.system.accumulation.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lavida.common.utils.security.ShiroUtils;
import com.lavida.framework.aspectj.lang.annotation.Log;
import com.lavida.framework.aspectj.lang.enums.BusinessType;
import com.lavida.framework.web.controller.BaseController;
import com.lavida.framework.web.page.TableDataInfo;
import com.lavida.project.system.accumulation.domain.Accumulation;
import com.lavida.project.system.accumulation.domain.Provident;
import com.lavida.project.system.accumulation.service.AccumulationService;
import com.lavida.project.system.dept.service.IDeptService;
import com.lavida.project.system.user.domain.User;
import com.lavida.project.system.user.service.IUserService;


@Controller
@RequestMapping("/system/accumulation")
public class AccumulationController extends BaseController{
	private String prefix = "system/accumulation";
	@Autowired
	private AccumulationService accumulationService;
	@Autowired
	private IUserService userService;
	@RequiresPermissions("wage:accumulation:view")
	@RequestMapping() 
	public String accu(ModelMap mmap) {
		User user  = ShiroUtils.getSysUser();
		User user1 = userService.selectUserById(user.getUserId());
		mmap.put("user", user1);
		return prefix+"/accumulation";
	}
	@RequiresPermissions("wage:accumulation:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Accumulation accumulation) {		
		startPage();
		List<Accumulation> selectAccumulation = accumulationService.selectAccumulation();	
		return getDataTable(selectAccumulation);
	}
	@RequiresPermissions("wage:accumulation:list")
	@PostMapping("/Prolist")
	@ResponseBody
	public Map<String, Object> proList(Provident provident) {		
		List<Provident> selectprovident= accumulationService.selectProvident();
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("providentList", selectprovident);
		return result;
	}
	@RequiresPermissions("wage:accumulation:list")
	@RequestMapping("/getAccu")
	@ResponseBody
	public Map<String, Object> editAccu(int id) {
		Accumulation accumulation = accumulationService.getId(id);
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("accumulation", accumulation);
		return result;
	}
	/**
	 * 更新操作
	 */
	@RequiresPermissions("wage:accumulation:update")
	@Log(title = "参数管理", businessType = BusinessType.UPDATE)
	@RequestMapping("/update")
	public String update(Accumulation accumulation) {
		System.out.println(accumulation.getCompanyRate()+"=============");
		accumulationService.updateAccu(accumulation);
		return "redirect:/system/accumulation";
	}
	
	/**
	 * 更新操作
	 */
	@Log(title = "参数管理", businessType = BusinessType.UPDATE)
	@RequiresPermissions("wage:accumulation:update")
	@RequestMapping("/updatePro")
	public String updateda(Provident provident,HttpServletRequest request) {
		System.out.println(provident.toString()+"=============");
		accumulationService.updatePro(provident);
		return "redirect:/system/accumulation";
	}
	
	
}
